//
//  TF_LivingImagePreviewView.swift
//  TalkfunSDKDemo
//
//  Created by 莫瑞权 on 2022/2/19.
//  Copyright © 2022 Talkfun. All rights reserved.
//

import UIKit

class TF_LivingImagePreviewView: UIView ,UIScrollViewDelegate,UIGestureRecognizerDelegate {
    
    @objc public var srcollView = UIScrollView()
    @objc public var imageView = UIImageView()
    @objc public var isAdd:Bool = false
     @objc func tapUiscrollView()
    {
        self.removeFromSuperview()
    }
    @objc public func layoutSubviewsUI(imageUrl:NSString)
    {
        if (self.isAdd == false ) {
            self.isAdd = true
            
    self.backgroundColor = UIColor.white
  
    let tapGesture = UITapGestureRecognizer.init(target: self, action: #selector(tapUiscrollView))
            //添加点按击手势监听器
        self.srcollView .addGestureRecognizer(tapGesture)
            
            //设置手势属性

           tapGesture.delegate = self;

           tapGesture.numberOfTapsRequired = 1;//设置点按次数，默认为1，注意在iOS中很少用双击操作

           tapGesture.numberOfTouchesRequired = 1;//点按的手指数


            
            self.srcollView.delegate = self

            self.srcollView.isUserInteractionEnabled = true

            self.srcollView.showsHorizontalScrollIndicator =  true//是否显示侧边的滚动栏

            self.srcollView.showsVerticalScrollIndicator = false

            self.srcollView.scrollsToTop = false
         
            self.srcollView.isScrollEnabled = true

            self.srcollView.frame = self.bounds;

            let ndwUrl = NSURL.init(string: imageUrl as String)
            
            self.imageView.sd_setImage(with: ndwUrl as URL? , completed: nil)
         

            self.imageView.contentMode = .scaleAspectFit //UIViewContentModeScaleAspectFit;
            //设置这个_imageView能被缩放的最大尺寸，这句话很重要，一定不能少,如果没有这句话，图片不能缩放

            self.imageView.frame = self.bounds

            self.addSubview(self.srcollView)

            self.srcollView.addSubview(self.imageView)

            self.srcollView.minimumZoomScale = 0.25
            self.srcollView.maximumZoomScale = 3.0
            self.srcollView.zoomScale = 1.0

           
        }
    }
   
 
}
